import DictService from "~/service/module/system/dict"
import { addForm } from "./_form_table"
import { Code } from "~/utils/enums"
import { ref } from "vue"

const useUpdate = () => {
    const dictService = new DictService()
    const dialogVisible = ref(false)
    const submit = async () => {
        const payload = addForm.getBindingValue()
        if (!addForm.dictId) {
            const res = await dictService.insertDict(payload)
            if (res.code === Code.SUCCESS) {
                $message.success('新增成功')
                dialogVisible.value = false
            }
        } else {
            const res = await dictService.updateDict({ dictId: addForm.dictId, ...payload })
            if (res.code === Code.SUCCESS) {
                $message.success('修改成功')
                dialogVisible.value = false
            }
        }
    }

    return {
        dialogVisible,
        submit
    }
}

export default useUpdate